package com.ruoyi.kjy.controller;/**
 * @InterfaceName: MainPageController
 * @Description:
 * @Author: YourName
 * @Date: 2023-04-11
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.kjy.domain.IntellectualProperty;
import com.ruoyi.kjy.domain.Introduction;
import com.ruoyi.kjy.mapper.IntroductionMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @InterfaceName: MainPageController
 * @Description:首页信息
 * @Author: lilirui
 * @Date: 2023-04-11
 */
@Api(tags = "首页信息")
@RestController
@RequestMapping("/mainpage")
public class MainPageController extends BaseController {

    @Autowired
    private IntroductionMapper introductionMapper;






//    @GetMapping(value = "getInfo")
//    public AjaxResult getInfo() {
//        return success(introductionMapper.selectById(1));
//    }
    /**
     * 获取首页详细信息
     */
    @GetMapping(value = "getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(introductionMapper.selectById(id));
    }

    @GetMapping("/list")
    public AjaxResult list(Long current, Long size, Introduction introduction) {
        QueryWrapper<Introduction> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(introduction);
        if (Objects.isNull(current)) {
            current = 1l;
        }
        if (Objects.isNull(size)) {
            size = 10l;
        }
        if (size >= 20l) {
            size = 20l;
        }
        return AjaxResult.success(introductionMapper.selectPage(new Page<>(current, size), queryWrapper));
    }



    @ApiOperation("入园条件信息")
    @GetMapping(value = "getEnterPark")
    public AjaxResult getEnterPark() {
        return success(introductionMapper.selectById(2));
    }

    /**
     * 修改首页
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Introduction introduction) {
        return toAjax(introductionMapper.updateById(introduction));
    }
}
